package com.controller;

import com.entity.User;
import com.service.UserService;
import com.service.impl.UserServiceImpl;
import com.util.json.Result;
import com.util.servlet.BaseController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 用户表现层
 */

public class UserController extends BaseController {
  private  UserService userService = new UserServiceImpl();

    /**
     * 登陆接口
     * @param user
     * @return
     */
    public String login(User user){


        try {
            User u = userService.login(user);
            //创建session
//            if(u != null) {
//                HttpServletRequest request = this.getRequest();
//                HttpSession session = request.getSession(true);
//                session.setAttribute("name",u.getAccount());
//            }

            return u == null ? Result.fial("帐号或密码错误") : Result.successObj(u);
        } catch (Exception e) {

            return Result.fial(e.getMessage());
        }

    }

    /**
     * 注册接口
     * @param user
     * @return
     */
    public String register(User user){
        try {
            User s = userService.register(user);
            if(s == null){
                return Result.success("帐号重复");
            }else{
                return Result.success("注册成功");

            }

        } catch (Exception e) {
            return Result.fial(e.getMessage());
        }

    }

    /**
     * 修改成功
     * @param name
     * @param oldPassword
     * @param newPassword
     * @return
     */
    public String update(String name,String oldPassword,String newPassword){

        return "成功";
    }

    public static void main(String[] args) {
        System.out.println(1!=1?"二":"三");


}
}

